from django.db import models
from django.contrib.auth.models import AbstractUser
from meiduo_mall.utils.models import BaseModel
from areas.models import AreaInfo


class User(AbstractUser):
    # 默认属性都有了，如用户名、密码、邮箱....
    # 定义新增的属性
    mobile = models.CharField(max_length=11)
    email_active = models.BooleanField(default=False)
    default_address = models.ForeignKey('AddressInfo', related_name='default_address', null=True)

    class Meta:
        db_table = 'tb_users'


class AddressInfo(BaseModel):
    title = models.CharField(max_length=10)
    receiver = models.CharField(max_length=10)
    province = models.ForeignKey(AreaInfo, related_name='provinces')
    city = models.ForeignKey(AreaInfo, related_name='cities')
    district = models.ForeignKey(AreaInfo, related_name='districts')
    place = models.CharField(max_length=50)
    mobile = models.CharField(max_length=11)
    tel = models.CharField(max_length=20, default='')
    email = models.CharField(max_length=20, default='')
    user = models.ForeignKey(User, related_name='addresses')

    class Meta:
        db_table = 'tb_addresses'
